﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ConceptsFramework.DerivedRelationships;
using PatternExplorer.DerivedConcepts;
using PatternExplorer.DerivedContainers;
using ConceptsFramework.ConceptResults;
using DPL.LogicalScript;

namespace DPL.PatternExplorer.UnitTests.LogicalScript
{

    [TestFixture]
    public class DynamicConceptSetPipeTests
    {
        /// <summary>
        /// Test CONTR(B)=A relationship to see if the right variable is 
        /// correcly computed (B is the right variable, and it should contain
        /// all the items in type A). Test with a single item only
        /// </summary>
        [Test]
        public void TestContrRelationship1()
        {
            TypeSummary AType = new TypeSummary();
            MethodSummary BMethod = new MethodSummary();
            AType.PublicMethods.Add(BMethod);
            TypeSummarySingletonContainer.Instance.Add(AType);
            DynamicConceptSetPipe<HostRelationship> HostRelationShipBinding = new DynamicConceptSetPipe<HostRelationship>();
            ResultSet leftRelationShipVariable = new ResultSet(AType);
            HostRelationShipBinding.LeftVariable = leftRelationShipVariable;
            bool test = HostRelationShipBinding.RightVariable.CurrentSet.Contains(BMethod);
            Assert.IsTrue(test);
            
        }

        /// <summary>
        /// Test CONTR(B)=A relationship to see if the right variable is 
        /// correcly computed (B is the right variable, and it should contain
        /// all the items in type A). Test with 2 items, one method and one 
        /// property
        /// </summary>
        [Test]
        public void TestContrRelationship2()
        {
            TypeSummary AType = new TypeSummary();
            MethodSummary BMethod = new MethodSummary();
            PropertySummary CProperty = new PropertySummary();
            AType.PublicMethods.Add(BMethod);
            AType.PublicProperties.Add(CProperty);
            TypeSummarySingletonContainer.Instance.Add(AType);
            DynamicConceptSetPipe<HostRelationship> HostRelationShipBinding = new DynamicConceptSetPipe<HostRelationship>();
            ResultSet leftRelationShipVariable = new ResultSet(AType);
            HostRelationShipBinding.LeftVariable = leftRelationShipVariable;
            bool test = (HostRelationShipBinding.RightVariable.CurrentSet.Contains(BMethod) &&
                        HostRelationShipBinding.RightVariable.CurrentSet.Contains(CProperty));
            Assert.IsTrue(test);

        }

        [Test]
        public void TestContrRelationship3WithLateBinding()
        {
            TypeSummary AType = new TypeSummary();
            MethodSummary BMethod = new MethodSummary();
            
            TypeSummarySingletonContainer.Instance.Add(AType);
            DynamicConceptSetPipe<HostRelationship> HostRelationShipBinding = new DynamicConceptSetPipe<HostRelationship>();
            ResultSet leftRelationShipVariable = new ResultSet(AType);
            HostRelationShipBinding.LeftVariable = leftRelationShipVariable;
            // Late bindings: the BMethod is linked after the LeftVariable has been defined.
            // An internal event should update the Right Variable automatically.
            AType.PublicMethods.Add(BMethod);

            bool test = HostRelationShipBinding.RightVariable.CurrentSet.Contains(BMethod);
            Assert.IsTrue(test);

        }
    }
}
